home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / basics / qtshell / common files / winframework.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  8.2 KB  |  238 lines

  1. //////////
  2. //
  3. //    File:        WinFramework.h
  4. //
  5. //    Contains:    Basic functions for windows, menus, and similar things.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on MDIPlayer sample code by Brian S. Friedkin (Aug 5, 1996).
  9. //
  10. //    Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <2>         11/02/98    rtm        minor reworking to coordinate with MacFramework.h
  15. //       <1>         07/03/96    rtm        first file; revised to personal coding style;
  16. //                                    renamed numerous types and parameters to mirror QTShell on MacOS
  17. //       
  18. //////////
  19.  
  20. #pragma once
  21.  
  22. // header files
  23.  
  24. #ifndef __Prefix_File__
  25. #include <WinPrefix.h>
  26. #endif
  27.  
  28. #ifndef _WINDOWS_
  29. #include <windows.h>
  30. #endif
  31.  
  32. #ifndef __FIXMATH__
  33. #include <FixMath.h>
  34. #endif
  35.  
  36. #ifndef __MOVIES__
  37. #include <Movies.h>
  38. #endif
  39.  
  40. #ifndef __RESOURCES__
  41. #include <Resources.h>
  42. #endif
  43.  
  44. #ifndef __QTML__
  45. #include <QTML.h>
  46. #endif
  47.  
  48. #ifndef __QUICKTIMEVR__
  49. #include <QuickTimeVR.h>
  50. #endif
  51.  
  52. #ifndef __SCRAP__
  53. #include <Scrap.h>
  54. #endif
  55.  
  56. #ifndef __SOUND__
  57. #include <Sound.h>
  58. #endif
  59.  
  60. #ifndef __TEXTUTILS__
  61. #include <TextUtils.h>
  62. #endif
  63.  
  64. #ifndef __QTUtilities__
  65. #include "QTUtilities.h"
  66. #endif
  67.  
  68.  
  69. //////////
  70. //
  71. // constants
  72. //
  73. //////////
  74.  
  75. #define    WM_PUMPMOVIE                (WM_USER+0)
  76. #define    WM_OPENDROPPEDFILES            (WM_USER+1)
  77. #define USEEXPLORERSTYLE            (LOBYTE(LOWORD(GetVersion()))>=4)
  78. #define kOpenDialogCustomData        11                        // an arbitrary value that allows our dialog proc to detect the Open File dialog box
  79. #define kAlertMessageMaxLength        256                        // maximum length of a message in the DoCautionAlert message box
  80.  
  81. #define kNewMovieName                "C:\\untitled.mov"        // default name of a movie created by "New" menu command
  82.  
  83. #define kInvalidFileRefNum            -1                        // an invalid file reference number
  84.  
  85. #define kWinFilePathSeparator        (char)'\\'                // on Windows, the file path separator is '\\'
  86.  
  87. // items in Save Changes dialog box
  88. #define kSaveChanges                IDYES                    // save the changes before closing window
  89. #define kCancelClose                IDCANCEL                // no, don't close the window or save changes
  90. #define kDontSaveChanges            IDNO                    // discard any unsaved changes
  91.  
  92. // constants for standard modal dialog filter proc
  93. #define kMyButtonDelay                8
  94. #define kReturnKey                    (char)0x0D    
  95. #define kEnterKey                    (char)0x03    
  96. #define kEscapeKey                    (char)0x1B    
  97. #define kPeriod                        '.'
  98.  
  99. // constants for selecting InitApplication phase
  100. enum {
  101.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window windows not yet created
  102.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window windows already created
  103.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  104. };
  105.  
  106. // constants for selecting StopApplication phase
  107. enum {
  108.     kStopAppPhase_BeforeDestroyWindows         = 1 << 0,        // movie windows not yet torn down
  109.     kStopAppPhase_AfterDestroyWindows        = 1    << 1,        // movie windows already torn down
  110.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  111. };
  112.  
  113. // parameters to the SetMenuItemState function
  114. #define kEnableMenuItem                MF_ENABLED
  115. #define kDisableMenuItem            MF_GRAYED
  116.  
  117. enum {
  118.     kMovieControllerObject          = FOUR_CHAR_CODE('MCvr')
  119. };
  120.  
  121.  
  122. //////////
  123. //
  124. // macros
  125. //
  126. //////////
  127.  
  128. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  129. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  130. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  131. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  132.  
  133.  
  134. //////////
  135. //
  136. // data types
  137. //
  138. //////////
  139.  
  140. typedef HMENU                MenuReference;
  141. typedef HWND                WindowReference;
  142.  
  143.  
  144. //////////
  145. //
  146. // structures
  147. //
  148. //////////
  149.  
  150. // WindowObjectRecord is a data structure attached to a movie window.
  151. // We use this structure to associate data with any window presented.
  152.  
  153. typedef struct {
  154.     WindowReference            fWindow;            // the window
  155.     OSType                    fObjectType;        // specific tag indicating that the window object belongs to our application
  156.     Movie                    fMovie;                // the main movie (QT or QTVR)
  157.     MovieController         fController;        // the movie controller for this window
  158.     FSSpec                    fFileFSSpec;        // location of the movie file
  159.     short                    fFileResID;
  160.     short                    fFileRefNum;
  161.     Boolean                    fCanResizeWindow;    // can the window be resized?
  162.     Boolean                    fDirty;                // has the movie data changed since the last save?
  163.     QTVRInstance            fInstance;            // the QTVRInstance
  164.     Handle                    fAppData;            // a handle to application-specific window data
  165. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  166.  
  167.  
  168. //////////
  169. //
  170. // function prototypes
  171. //       
  172. //////////
  173.  
  174. LRESULT CALLBACK             FrameWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam);
  175. LRESULT CALLBACK             MovieWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam);
  176. BOOL                        GetFile (char *theFileName);
  177. int                            AdjustMenus (HWND theWnd, HMENU theMenu);
  178. void                        QuitFramework (void);
  179.  
  180. Boolean                     DoCreateNewMovie (void);
  181. MovieController                SetupMovieWindowWithController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  182. void                        DoOpenCommandLineMovies (LPSTR theCmdLine);
  183. BOOL                        DoCreateMovieWindow (Movie theMovie, FSSpec *theFSSpec);
  184. OSErr                        DoSaveAsMovieFile (WindowReference theWindow);
  185. Boolean                        DoUpdateMovieFile (WindowReference theWindow);
  186. static void                    DoCut (HWND theWnd);
  187. static void                    DoCopy (HWND theWnd);
  188. static void                    DoPaste (HWND theWnd);
  189. static void                    DoClear (HWND theWnd);
  190. static void                    DoUndo (HWND theWnd);
  191. static void                    GetDisplayName (char *thePathName, char *theFileName);
  192.  
  193. void                        SizeWindowToMovie (WindowObject theWindowObject);
  194. static void                    ShowAboutBox (void);
  195. int                            DoCautionAlert (HWND theWnd, UINT theID, UINT theIconStyle, UINT theButtonStyle, LPSTR theTitle, LPSTR theArgument);
  196. static UINT APIENTRY        DialogProc (HWND theDialog, UINT theMessage, WPARAM wParam, LPARAM lParam);
  197. static void                    CalcWindowMinMaxInfo (HWND theWnd, LPMINMAXINFO lpMinMax);
  198. static void                    SetWindowTitleFromFSSpec (HWND theWnd, FSSpec *theFSSpec, Boolean theAddToRecentDocs);
  199.  
  200. WindowReference                GetFrontMovieWindow (void);
  201. WindowReference                GetNextMovieWindow (WindowReference theWindow);
  202. WindowObject                GetWindowObjectFromFrontWindow (void);
  203. WindowObject                GetWindowObjectFromWindow (WindowReference theWnd);
  204. MovieController              GetMCFromFrontWindow (void);
  205. MovieController                GetMCFromWindow (WindowReference theWindow);
  206. QTVRInstance                GetQTVRInstanceFromFrontWindow (void);
  207. Handle                        GetAppDataFromFrontWindow (void);
  208. Handle                        GetAppDataFromWindow (WindowReference theWnd);
  209. Handle                        GetAppDataFromWindowObject (WindowObject theWindowObject);
  210. Boolean                     IsWindowObjectOurs (WindowObject theWindowObject);
  211. void                        DoBeep (void);
  212. void                        SetMenuState (MenuReference theMenu, UInt16 theMenuRank, short theState);
  213. void                        SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  214. void                        SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  215. void                        SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  216. GrafPtr                        GetPortFromWindowReference (WindowReference theWindow);
  217. WindowReference                GetWindowReferenceFromPort (GrafPtr thePort);
  218. short                        GetWindowWidth (WindowReference theWindow);
  219. WindowReference                GetFrontAppWindow (void);
  220. WindowReference                GetNextAppWindow (WindowReference theWindow);
  221.  
  222.  
  223. // application-specific functions
  224. // These are defined in the ComApplication.c file;
  225. // you could override these to change the behavior of the function in a specific application.
  226. void                        InitApplication (UInt32 theStartPhase);
  227. void                        StopApplication (UInt32 theStopPhase);
  228. void                        DoIdle (WindowReference theWindow);
  229. void                        DoUpdateWindow (WindowReference theWindow, Rect *theRefrehArea);
  230. void                         HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  231. Boolean                        HandleApplicationKeyPress (char theCharCode);
  232. void                         HandleApplicationMenu (UInt16 theMenuItem);
  233. void                        AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu);
  234. Boolean                        DoApplicationEventLoopAction (EventRecord *theEvent);
  235. void                        AddControllerFunctionality (MovieController theMC);
  236. void                        InitApplicationWindowObject (WindowObject theWindowObject);
  237. void                        RemoveApplicationWindowObject (WindowObject theWindowObject);
  238. PASCAL_RTN Boolean             ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);